<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>任务列表</title>


    <link type="text/css" href="/TopJUI/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/TopJUI/topjui/themes/default/topjui.green.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/TopJUI/topjui/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/TopJUI/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/TopJUI/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/TopJUI/topjui/js/locale/topjui.lang.zh_CN.js"></script>

    <script type="text/javascript" src="/pages/js/moment.min.js"></script>
    <script type="text/javascript" src="/pages/js/layer/layer.js"></script>
    <script type="text/javascript" src="/pages/js/util.js"></script>

    <script type="text/javascript" src="/pages/js/base-loading.js"></script>
    <script type="text/javascript" src="/pages/js/shuoheUtil.js"></script>

    <style type="text/css">
        html, body{ margin:0; height:100%; }
    </style>

</head>
<body class="easyui-layout">

  <!--   <div data-options="region:'west',iconCls:'icon-reload',title:'',split:true" style="width:15%;">           
        <table id="tt" style="height:100%;width: 100%;" title="" data-options="
                  idField:'id',
                  treeField:'project_name',
                  method:'get'
                ">
          <thead>
              <tr>
                  <th field="project_name" width="100%">职位</th>
                  <th field="id" width="0px" hidden="true">序列</th>
              </tr>
          </thead>
        </table>        
    </div> -->

    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:100%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:100%;height:100%" title="" data-options="
                  rownumbers:true,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:false,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:false,
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
                    <th field="id" align="center" hidden ="true">id</th>
                    <th field="project_id" align="center">项目编号</th>
                    <th field="project_name">项目名称</th>
                    <th field="plan_content" width="200">任务内容</th>
                    <th field="task_level_1" width="200">一级分解</th>
                    <th field="task_level_2" width="200">二级分解</th>
                    <th field="task_level_3" width="200">三级分解</th>
                    <th field="plan_start_date" formatter='datagridFormatDateYMD'>任务开始时间</th>
                    <th field="plan_end_date" formatter='datagridFormatDateYMD'>任务结束时间</th>
                    <th field="finish_date" formatter='datagridFormatDateYMD'>任务完成时间</th>
                    <th field="is_finish" align="center" formatter='formateStatus'>状态</th>
                    <th field="date" formatter='formateDate'>距今时间</th>
              </tr>
            </thead>
          </table>
          <div id="tb" style="height:35px">            
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-check',plain:true" onclick="finish()" style="margin-left: 30px">完成</a>
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-mouse-pointer',plain:true" onclick="view()">查看</a>            
            <form id="queryForm" class="search-box">
              </form>            
          </div>
       </div>
    </div>




  <script type="text/javascript">
    var project = new Object();


    $(function(){
        $.ajax({
            url: '/system/user/getUser.do',
            success: function(data) {
                console.info(data);       
                $('#dg').datagrid({
                    url: '/develop/url/getUrl.do',
                    queryParams: {
                        name: 'getTaskByUserId',
                        user_id: data.id
                    },
                    method: 'get',
                    onDblClickCell:function(index,field,value){
                        view();
                    }
                })                            
            }
        });
    });
    

    var formateStatus = function(val,row)
    {
        if(row.is_finish == true && row.finish_date > row.plan_end_date)
            return '<font color="orange"><i class="fa fa-calendar-times-o"></i>延迟</font>';     
        if(row.is_finish == true)
            return '<font color="green"><i class="fa fa-calendar-check-o"></i>准时</font>';     
        // if(row.is_finish == false && !shuoheUtil.checkNull(row.finish_date))
        //     return '<font color="red"><i class="fa fa-calendar-times-o text-danger"></i></font>';

    }
    var formateDate = function(val,row)
    {
        if(row.is_finish == false)
            return moment(row.plan_end_date).diff(moment(), 'days')        
    }
    function finish()
    {
        var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layerMsgCustom('必须选择一条数据');
          return;
        }
        layer.open({
            type: 2,
            title: '完成任务',
            shadeClose: false,
            btn: '保存',
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['500px','400px'],
            content: 'form/finishWorkTask.jsp?masterplan_id=' + row.masterplan_id,
            yes: function(index) {
                var ifname = "layui-layer-iframe" + index //获得layer层的名字
                var Ifame = window.frames[ifname] //得到框架
                Ifame.save();
            }
        })
    }
	</script>




</body>
</html>
<script type="text/javascript">
    function add() {
      layer.open({
          type: 2,
          title: '新增设备',
          shadeClose: false,
          shade: 0.3,
          maxmin: true, //开启最大化最小化按钮s
          area: ['800px','500px'],
          content: 'form/addPlan.jsp?id='+project.id
      })
    }
  function view()
  {
      var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layerMsgCustom('必须选择一条数据');
          return;
        }

        layer.open({
            type: 2,
            // title: '查看详情',
            shadeClose: true,
            shade: 0.3,
            // maxmin: true, //开启最大化最小化按钮
            area: ['800px', (document.body.clientHeight - 100)+'px'],
            content: 'form/workTaskView.jsp?id=' + row.masterplan_id+'&project_id='+row.id
        })
  }

    function edit() {

        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '修改设备',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px','400px'],
            content: 'form/editPlan.jsp?id=' + row.id+'&project_id='+ project.id
        })
    }
    function dele() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        //删除操作属于危险操作，给出提示
        $.messager.confirm('友情提示', '您确定要删除这条数据吗?', function(r) {
            if (r) {
                shuoheUtil.layerTopMaskOn();
                $.ajax({
                    url: "/mro/equipment/equipment/delete.do",
                    type: "POST",
                    dataType: 'json',
                    data: {
                        'id': row.id
                    },
                    error: function() //失败
                    {
                        shuoheUtil.layerTopMaskOff();
                    },
                    success: function(data) //成功
                    {
                        updateSuccess();
                        shuoheUtil.layerTopMaskOff();
                        if(data.result)
                        {
                            shuoheUtil.layerMsgOK(data.describe);
                        }
                        else
                        {
                            shuoheUtil.layerMsgError(data.describe);
                        }
                    }
                });
            }
        });
    }


  function updateSuccess()
  {
    $('#dg').datagrid('reload');

  }
  
  
  function functionQuery() {
	    loadDg();
	  }
	  function functionClear() {
	    $('#equipment_id').textbox('clear');
	    $('#equipment_name').textbox('clear');
	    $('#use_department').textbox('clear');
	    $('#actual_name').textbox('clear');
	    loadDg();
	  }


</script>
